﻿using System;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using System.Collections.ObjectModel;


namespace cz.uhul.DSMLv2
{




  /// <summary>
  /// can contain only one of operators, not multiple
  /// so no collection but just values
  /// </summary>
  public class FilterGroup : FilterOp
  {


    public FilterGroup()
      : base()
    { }





    [XmlElement(ElementName = "and", Form = XmlSchemaForm.None, IsNullable = false, Type = typeof(AndOp))]
    public AndOp And
    {
      get
      {
        return (Operation is AndOp) ? (AndOp)Operation : null;
      }
      set
      {
        if (Operation != null)
          throw new InvalidSearchFilterException("cant set 'and', " + Operation.OpTypeName + " allready exists");

        Operation = value;
      }
    }




    [XmlElement(ElementName = "or", Form = XmlSchemaForm.None, IsNullable = false, Type = typeof(OrOp))]
    public OrOp Or
    {
      get
      {
        return (Operation is OrOp) ? (OrOp)Operation : null;
      }
      set
      {
        if (Operation != null)
          throw new InvalidSearchFilterException("cant set 'or', " + Operation.OpTypeName + " allready exists");

        Operation = value;
      }
    }




    [XmlElement(ElementName = "not", Form = XmlSchemaForm.None, IsNullable = false, Type = typeof(NotOp))]
    public NotOp Not
    {
      get
      {
        return (Operation is NotOp) ? (NotOp)Operation : null;
      }
      set
      {
        if (Operation != null)
          throw new InvalidSearchFilterException("cant set 'not', " + Operation.OpTypeName + " allready exists");

        Operation = value;
      }
    }




    [XmlElement(ElementName = "present", Form = XmlSchemaForm.None, IsNullable = false, Type = typeof(PresentOp))]
    public PresentOp Present
    {
      get
      {
        return (Operation is PresentOp) ? (PresentOp)Operation : null;
      }
      set
      {
        if (Operation != null)
          throw new InvalidSearchFilterException("cant set 'present', " + Operation.OpTypeName + " allready exists");

        Operation = value;
      }
    }




    [XmlElement(ElementName = "substrings", Form = XmlSchemaForm.None, IsNullable = false, Type = typeof(SubstringsOp))]
    public SubstringsOp Substrings
    {
      get
      {
        return (Operation is SubstringsOp) ? (SubstringsOp)Operation : null;
      }
      set
      {
        if (Operation != null)
          throw new InvalidSearchFilterException("cant set 'substrings', " + Operation.OpTypeName + " allready exists");

        Operation = value;
      }
    }




    [XmlElement(ElementName = "equalityMatch", Form = XmlSchemaForm.None, IsNullable = false, Type = typeof(EqualityMatchOp))]
    public EqualityMatchOp EqualityMatch
    {
      get
      {
        return (Operation is EqualityMatchOp) ? (EqualityMatchOp)Operation : null;
      }
      set
      {
        if (Operation != null)
          throw new InvalidSearchFilterException("cant set 'equalityMatch', " + Operation.OpTypeName + " allready exists");

        Operation = value;
      }
    }





    [XmlIgnore]
    public FilterOp Operation { get; set; }

  }

}
